%% -*- erlang -*-
{erl_opts, [
            debug_info,
            {parse_transform, lager_transform},
            {i, "./_build/default/plugins/gpb/include"}
           ]}.

{cover_export_enabled, true}.
{cover_enabled, true}.

{deps, [
        {blockchain, {git, "https://github.com/helium/blockchain-core.git",
                      {branch, "master"}}},
        {sibyl, {git, "https://github.com/helium/sibyl.git",
                      {branch, "master"}}},
        {hbbft, {git, "https://github.com/helium/erlang-hbbft.git",
                 {branch, "master"}}},
        {dkg, {git, "https://github.com/helium/erlang-dkg.git", {branch, "master"}}},
        {ecc508, {git, "https://github.com/helium/ecc508.git", {branch, "master"}}},
        {ebus, {git, "https://github.com/helium/ebus.git", {branch, "master"}}},
        {jsx, "3.1.0"},
        {kvc, {git, "https://github.com/etrepum/kvc", {tag, "v1.7.0"}}},
        {longfi, {git, "https://github.com/helium/longfi-erlang", {tag, "0.2.1"}}},
        recon,
        {elli, "3.3.0"},
        {jsonrpc2, {git, "https://github.com/zuiderkwast/jsonrpc2-erlang",
                 {branch, "master"}}}
       ]}.

{xref_checks, [
               undefined_function_calls,
               undefined_functions,
               %locals_not_used,
               deprecated_function_calls,
               deprecated_functions
              ]}.

{plugins, [
           {rebar3_gpb_plugin, "2.15.0"},
           {rebar3_eqc, "1.3.0"}
          ]}.

{gpb_opts, [
    {i, "src"},
    {o_erl, "src/pb"},
    {o_hrl, "src/pb"},
    {msg_name_prefix, "miner_"},
    {msg_name_suffix, "_pb"},
    {module_name_suffix, "_pb"},
    {strings_as_binaries, false},
    type_specs
]}.

{provider_hooks, [
    {pre, [
        {compile, {protobuf, compile}},
        {clean, {protobuf, clean}}
    ]}
]}.

{relx, [
        {release, {'miner', git},
         [miner, runtime_tools, tools, recon]},
        {overlay,
         [
          {copy, "scripts/extensions/genesis", "bin/extensions/genesis"},
          {copy, "scripts/extensions/hbbft", "bin/extensions/hbbft"},
          {copy, "scripts/extensions/info", "bin/extensions/info"},
          {copy, "scripts/extensions/dkg", "bin/extensions/dkg"},
          {copy, "scripts/extensions/authorize", "bin/extensions/authorize"},
          {copy, "scripts/extensions/print_keys", "bin/extensions/print_keys"},
          {copy, "./_build/default/lib/blockchain/scripts/extensions/peer", "bin/extensions/peer"},
          {copy, "./_build/default/lib/blockchain/scripts/extensions/snapshot", "bin/extensions/snapshot"},
          {copy, "./_build/default/lib/blockchain/scripts/extensions/ledger", "bin/extensions/ledger"},
          {copy, "./_build/default/lib/blockchain/scripts/extensions/trace", "bin/extensions/trace"},
          {copy, "./_build/default/lib/blockchain/scripts/extensions/txn", "bin/extensions/txn"},
          {copy, "./_build/default/lib/blockchain/scripts/extensions/repair", "bin/extensions/repair"},
          {template, "config/vm.args", "{{output_dir}}/releases/{{release_version}}/vm.args"}
         ]},
        {extended_start_script_hooks,
         [
          {post_start,
           [
            {wait_for_process, blockchain_worker}
           ]}
         ]},
        {extended_start_script, true},
        {extended_start_script_extensions,
         [
          {genesis, "extensions/genesis"},
          {hbbft, "extensions/hbbft"},
          {peer, "extensions/peer"},
          {snapshot, "extensions/snapshot"},
          {ledger, "extensions/ledger"},
          {info, "extensions/info"},
          {trace, "extensions/trace"},
          {txn, "extensions/txn"},
          {dkg, "extensions/dkg"},
          {authorize, "extensions/authorize"},
          {repair, "extensions/repair"},
          {print_keys, "extensions/print_keys"}
         ]},
        {dev_mode, true},
        {include_erts, false}
       ]}.

{profiles, [
            %% for test and run.sh
            {testdev,
             [
              {relx, [
                      {sys_config, "./config/test.config"},
                      {overlay,
                       [{copy, "config/sys.config", "config/sys.config"}]},
                      {dev_mode, true},
                      {include_erts, false}]
              }]},
            %% for syncing local miners
            {dev,
             [
              {relx, [
                      {release, {'miner', git},
                       [miner, observer, runtime_tools, tools,wx, recon]},
                      {sys_config, "./config/dev.config"},
                      {overlay,
                       [{copy, "config/sys.config", "config/sys.config"}]},
                      {dev_mode, true},
                      {include_erts, false}]
              }]},
            {aws, [
                   {relx, [
                           {sys_config, "./config/aws.config"},
                           {overlay,
                            [{copy, "config/sys.config", "config/sys.config"}]},
                           {dev_mode, true},
                           {include_erts, false}]}]
            },
            {seed, [
                   {relx, [
                           {sys_config, "./config/seed.config"},
                           {overlay,
                            [{copy, "config/sys.config", "config/sys.config"}]},
                           {dev_mode, true},
                           {include_erts, false}]}]
            },
            {docker, [
              {relx, [
                {release, {miner, git},
                  [miner,
                    tools,
                    runtime_tools,
                    recon]},
                {sys_config, "./config/docker.config"},
                {overlay,
                  [{copy, "config/sys.config", "config/sys.config"}]},
                {dev_mode, false},
                {include_src, false},
                {include_erts, true}]}]
            },
            {miner1, [{relx, [{release, {'miner1', git}, [miner, observer, runtime_tools, tools, wx, recon]},
                              {sys_config, "./config/test.config"},
                              {overlay,
                               [{template, "config/vm_dev.args",
                                 "{{output_dir}}/releases/{{release_version}}/vm.args"}]}]}]},
            {miner2, [{relx, [{release, {'miner2', git}, [miner, observer, runtime_tools, tools, wx, recon]},
                              {sys_config, "./config/test.config"},
                              {overlay,
                               [{template, "config/vm_dev.args",
                                 "{{output_dir}}/releases/{{release_version}}/vm.args"}]}]}]},
            {miner3, [{relx, [{release, {'miner3', git}, [miner, observer, runtime_tools, tools, wx, recon]},
                              {sys_config, "./config/test.config"},
                              {overlay,
                               [{template, "config/vm_dev.args",
                                 "{{output_dir}}/releases/{{release_version}}/vm.args"}]}]}]},
            {miner4, [{relx, [{release, {'miner4', git}, [miner, observer, runtime_tools, tools, wx, recon]},
                              {sys_config, "./config/test.config"},
                              {overlay,
                               [{template, "config/vm_dev.args",
                                 "{{output_dir}}/releases/{{release_version}}/vm.args"}]}]}]},
            {miner5, [{relx, [{release, {'miner5', git}, [miner, observer, runtime_tools, tools, wx, recon]},
                              {sys_config, "./config/test.config"},
                              {overlay,
                               [{template, "config/vm_dev.args",
                                 "{{output_dir}}/releases/{{release_version}}/vm.args"}]}]}]},
            {miner6, [{relx, [{release, {'miner6', git}, [miner, observer, runtime_tools, tools, wx, recon]},
                              {sys_config, "./config/test.config"},
                              {overlay,
                               [{template, "config/vm_dev.args",
                                 "{{output_dir}}/releases/{{release_version}}/vm.args"}]}]}]},
            {miner7, [{relx, [{release, {'miner7', git}, [miner, observer, runtime_tools, tools, wx, recon]},
                              {sys_config, "./config/test.config"},
                              {overlay,
                               [{template, "config/vm_dev.args",
                                 "{{output_dir}}/releases/{{release_version}}/vm.args"}]}]}]},
            {miner8, [{relx, [{release, {'miner8', git}, [miner, observer, runtime_tools, tools, wx, recon]},
                              {sys_config, "./config/test.config"},
                              {overlay,
                               [{template, "config/vm_dev.args",
                                 "{{output_dir}}/releases/{{release_version}}/vm.args"}]}]}]},
            {prod, [
                    {relx, [
                            {release, {miner, git},
                             [miner,
                              tools,
                              runtime_tools,
                              recon]},
                            {sys_config, "./config/sys.config"},
                            {dev_mode, false},
                            {include_src, false},
                            {system_libs, false},
                            {include_erts, false}]}]
            },
            {validator,
             [
              {relx,
               [
                {release, {miner, {semver, "validator"}},
                 [miner,
                  tools,
                  runtime_tools,
                  recon]},
                {sys_config_src, "config/val.config.src"},
                %% {vm_args_src, "config/vm_val.args.src"},
                {overlay,
                 [{copy, "config/sys.config", "config/sys.config"},
                  {template, "config/vm_val.args", "{{output_dir}}/releases/{{release_version}}/vm.args"}]},
                {dev_mode, false},
                {include_erts, true},
                {extended_start_script, true},
                {include_src, false}]}]
            },
            {test_validator,
             [
              {relx,
               [
                {release, {miner, git},
                 [miner,
                  tools,
                  runtime_tools,
                  recon]},
                {sys_config_src, "config/test_val.config.src"},
                %% {vm_args_src, "config/vm_val.args.src"},
                {overlay,
                 [{copy, "config/sys.config", "config/sys.config"},
                  {template, "config/vm_val.args", "{{output_dir}}/releases/{{release_version}}/vm.args"}]},
                {dev_mode, false},
                {include_erts, true},
                {extended_start_script, true},
                {include_src, false}]}]
            },
            {docker_val, [
              {relx, [
                {release, {miner, {semver, "validator"}},
                  [miner,
                    tools,
                    runtime_tools,
                    recon]},
                {sys_config_src, "./config/docker-val.config.src"},
                %% {vm_args_src, "config/vm_val.args.src"},
                {overlay,
                 [{copy, "config/sys.config", "config/sys.config"},
                  {template, "config/vm_val.args", "{{output_dir}}/releases/{{release_version}}/vm.args"}]},
                {dev_mode, false},
                {include_src, false},
                {include_erts, true}]}]
            },
            {docker_testval, [
              {relx, [
                {release, {miner, {semver, "val"}},
                  [miner,
                    tools,
                    runtime_tools,
                    recon]},
                {sys_config_src, "./config/docker-testval.config.src"},
                %% {vm_args_src, "config/vm_val.args.src"},
                {overlay,
                 [{copy, "config/sys.config", "config/sys.config"},
                  {template, "config/vm_val.args", "{{output_dir}}/releases/{{release_version}}/vm.args"}]},
                {dev_mode, false},
                {include_src, false},
                {include_erts, true}]}]
            },
            {test,
             [
              {overrides, [{add, blockchain, [{erl_opts, [{d, 'TEST'}]}]}]},
              {erl_opts, [nowarn_export_all]},
              {deps, [
                  {meck, "0.8.12"},
                  {grpc_client, {git, "https://github.com/Bluehouse-Technology/grpc_client.git", {branch, "master"}}}
              ]}
             ]}
]}.

{ct_opts,
 [{sys_config, "config/test.config"}]}.
